package xyz.xtt.exchange.constants;

import java.util.Arrays;
import java.util.Objects;

import com.google.common.primitives.Ints;

/**
 * @author huqibo
 * 
 *         资产类型枚举
 */
public enum OrderTypeEnum {
	NORMAL(0, "正常订单"), AFTER_ADD(1, "加购订单");

	private int code;
	private String desc;

	// 构造函数
	OrderTypeEnum(int code, String desc) {
		this.code = code;
		this.desc = desc;
	}

	public int code() {
		return code;
	}

	// 获取描述
	public String desc() {
		return desc;
	}

	public static boolean checkType(String checkType) {
		return Arrays.asList(OrderTypeEnum.values()).stream().anyMatch(x -> Objects.equals(x.name(), checkType));
	}

	public static OrderTypeEnum convert(String checkType) {
		return Arrays.asList(OrderTypeEnum.values()).stream().filter(x -> Objects.equals(x.name(), checkType))
				.findFirst().orElse(null);
	}

	public static OrderTypeEnum queryConvert(String checkType) {
		return Arrays.asList(OrderTypeEnum.values()).stream()
				.filter(x -> Objects.equals(x.code(), Ints.tryParse(checkType))).findFirst().orElse(null);
	}

}
